import sys
sys.stdout.reconfigure(encoding='utf-8')
from sklearn.feature_extraction.text import TfidfVectorizer

chinese_text = sys.argv[1]
tfidf_vectorizer = TfidfVectorizer()
tfidf_matrix = tfidf_vectorizer.fit_transform([chinese_text])
feature_names = tfidf_vectorizer.get_feature_names_out()
# 获取关键词及其对应的 TF-IDF 值
keywords_tfidf = [(feature_names[col], tfidf_matrix[0, col]) for col in tfidf_matrix.nonzero()[1]]
# 按 TF-IDF 值排序关键词
keywords_tfidf.sort(key=lambda x: x[1], reverse=True)
# print(feature_names)
print([keywords_tfidf[i][0] for i in range(5)])


